/**
 * @author wangjingjing

 */
var sort = null;
var grid = null;

function initlist(){
	var colModel = new Ext.grid.ColumnModel([
	                                 		{header:'收文编号',dataIndex:'shouwenbianhao',menuDisabled : true,width: 35},
	                                 		{header:'来文机关',dataIndex:'laiwenjiguan',menuDisabled : true,width: 50},
	                                 		{header:'来文字号',dataIndex:'laiwenzihao',menuDisabled : true,width: 35},		
	                                 		{header:'标题',dataIndex:'zhaiyou',menuDisabled : true},
	                                 		{header:'来文日期',dataIndex:'shouwenriqi',menuDisabled : true,width: 50}
	                                 	]);
//	var url = Ext.get('url').getValue();
	   var myDate = new Date();
       var _yearNo= myDate.getFullYear();
       var _beginNo='1';
       var _endNo='200';
       var _doctype='党字';
       
	sort = new Ext.data.JsonStore({
		
		url:encodeURI(encodeURI(Ext.get('basePath').getValue()+ 'tjsinfo/tjsoa/dangweishouwen/dengjibu.do?method=dengjibuSearch&yearNO=' + _yearNo + '&beginNO='+_beginNo+'&endNO='+_endNo+'&doctype='+_doctype,"UTF-8"),"UTF-8"),
		fields:['shouwenbianhao','shouwenriqi','laiwenzihao','laiwenjiguan','zhaiyou'],
		root:'root',
		totalProperty:'totalProperty'
	});
	/*  动态获取文件种类      */

//	var typestore = new Ext.data.JsonStore({
//		fields: ['id','typeName'],
//		url: Ext.get('basePath').getValue()+ 'tjsinfo/tjsoa/xingzhengfawen/selectTypeByItem.do?itemType='+_itemtype
//	});
//	typestore.on('load', function() {    
//		_doctype=typestore.getAt(0).get('id');
//		Ext.getCmp('comtype').setValue(_doctype);
//		 });
//	typestore.load();
	
	 grid = new Ext.grid.GridPanel({
		title:'党委收文登记薄查询记录',
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		autoHeight:true,
	    viewConfig:{
	    	forceFit: true
	    },
	    loadMask:{ 
		msg : '数据加载中，请稍后...' 
		}, 
	    stripeRows:true,
	    width: Ext.get("topic-grid").getWidth(),
	    height:Ext.get("topic-grid").getHeight(),
	    tbar: new Ext.Toolbar({
         items: [
                {   text: '请输入检索条件：文件类型:'
                },{ 
                	name:'comtype',
                	id:'comtype',
                	xtype:'combo',
                	mode: 'local',
      	            store:  new Ext.data.SimpleStore({ fields: ['id', 'typeName'], data: [['1', '党字']]   }),
      	            valueField:'typeName',
      	            displayField:'typeName',
      	            value:_doctype,
                	triggerAction: 'all',
                	editable:false,
                	readOnly:false,
                	width:200 
                },{ 
                	text: '年度：'
                },{ 
                	name:'txtyear',
                	id:'txtyear',
                	xtype:'textfield',
                	value:_yearNo,
					width:50 
                },{ 
                	text: '起始收文编号：'
                },{ 
                	name:'beginNO',
                	id:'beginNO',
                	xtype:'textfield',
                	value:_beginNo,
					width:50       
					  },{ 
                	text: '终止收文编号：'
                },{ 
                	name:'endNO',
                	id:'endNO',
                	xtype:'textfield',
                	value:_endNo,
                	
					width:50       
                },{
                	text: '检索',
                	iconCls:'search',
			            handler: function(){
						    _yearNo = Ext.getCmp('txtyear').getValue();
						    _beginNo = Ext.getCmp('beginNO').getValue();
						    _endNo = Ext.getCmp('endNO').getValue();
						    _doctype = Ext.getCmp('comtype').getValue();
						    if(!/^[2-9][0-9]{3}$/.test(_yearNo)) 
							{
								Ext.MessageBox.alert('提示', '请输入正确的查询年限,如2012!');
								return;
							}
							if(!(_beginNo==null || _beginNo.length==0)){
//								Ext.MessageBox.alert('提示', '请输入起始发文号!');
//								return;
//							}else{
								if(!/^[1-9][0-9]*$/.test(_beginNo)) 
								{
									Ext.MessageBox.alert('提示', '请输入正确的起始收文编号,只能为数字!');
									return;
								}
							}
							if(!(_endNo==null || _endNo.length==0)){
//								Ext.MessageBox.alert('提示', '请输入结束发文号!');
//								return;
//							}else{
								if(!/^[1-9][0-9]*$/.test(_endNo)) 
								{
									Ext.MessageBox.alert('提示', '请输入正确的结束收文编号,只能为数字!');
									return;
								}
							}
						    sort.removeAll();
			                sort.proxy = new Ext.data.HttpProxy({url:encodeURI(encodeURI(Ext.get('basePath').getValue()+ 'tjsinfo/tjsoa/dangweishouwen/dengjibu.do?method=dengjibuSearch&yearNO=' + _yearNo + '&beginNO='+_beginNo+'&endNO='+_endNo +'&doctype='+_doctype,"UTF-8"),"UTF-8")});
			              	sort.reload(); 
			                }
			   },'->', 	{
               id: 'buttonB',
		       iconCls: 'daohang',
               text: "导出",
               handler: function() {
					exportExcel("title","test");
               }
			},{ 
//				id: 'buttonC',
//		       iconCls: 'daohang',
//               text: "归档文件目录",
//               handler: function() {
//					ExportExcel("title","test");
//               }
//			},{
               id: 'buttonA',
		       iconCls: 'daohang',
               text: "返回",
               handler: function() {
					window.history.go(-1);
               }
			}]
		})
	});
	sort.load();
	
	var exportExcel = function(title,fileName){  
       var vExportContent = grid.getExcelXml(title);  
  //alert(vExportContent);    
  
        if (Ext.isIE6 || Ext.isIE7 ||  Ext.isIE8 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {  
            var fd=Ext.get('frmDummy');  
            if (!fd) {  
                fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'frmDummy',action:'articles/js/gridtoexcel.jsp', target:'_blank',name:'frmDummy',cls:'x-hidden',cn:[  
                    {tag:'input',name:'fileName',id:'fileName',type:'hidden'},  
                    {tag:'input',name:'exportContent',id:'exportContent',type:'hidden'}  
                ]},true);  
            }  
            fd.child('#fileName').set({value:fileName});  
            fd.child('#exportContent').set({value:vExportContent});  
            fd.dom.submit();  
        } else {  
            document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode(vExportContent);  
  }}  
	
}